<?php
namespace app\task\controller;

use app\task\model\Order as OrderModel;
use app\task\model\Setting;

/**
 * 第三方配送异步通讯接口
 */

class Delivery
{
	/**
     * 顺丰异步通知处理
     */
    public function sf()
    {
		$sign = $_GET['sign'];
        $data = file_get_contents('php://input');
        $config = Setting::getItem('webdelivery',0)['sf'];
        if($sign && $sign == base64_encode(MD5("{$data}&{$config['app_key']}&{$config['app_secret']}"))){
            $data = json_decode($data,true);
            $model = (new OrderModel)->with(['delivery'])->where('order_no',$data['shop_order_id'])->find();
            $model->updateDeliveryStatus($data,'sf');
            return true;
        }else {
            return false;
        }
    }

    /**
     * 达达异步通知处理
     */
    public function dada()
    {
		$data = file_get_contents('php://input' );
		$data = json_decode($data,true);
        $model = (new OrderModel)->with(['delivery'])->where('order_no',$data['order_id'])->find();
		$model->updateDeliveryStatus($data,'dada');
        return true;
    }

    /**
     * UU异步通知处理
     */
    public function uu()
    {
		$data = $_POST['data'];
        $model = (new OrderModel)->with(['delivery'])->where('order_no',$data['origin_id'])->find();
		$model->updateDeliveryStatus($data,'uu');
        return true;
    }
}
